﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using TcpTestServer.DataLayer;

namespace TcpTestServer
{
    class Program
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new ServerMainForm());
        }
        //static void Main(string[] args)
        //{


        //    //foreach (XmlProtocol Component in RsdComponents)
        //    //{
        //    //    Component.ConnectionEvent += new ConnectionDel(xml_ConnectionEvent);
        //    //    Component.MessageSent += new MessageCallbackDel(xml_MessageSent);
        //    //    Component.ResponseReceived += new MessageCallbackDel(xml_ResponseReceived);
        //    //}
        //    ServerMainForm ServerGui = new ServerMainForm();

        //    Application.Run(ServerGui);
        //    ServerGui.Show();


            

        //}

      
/*
        public static void sendTestMessage(XmlProtocol Component)
        {
            if (Component.Connected && Component.IsReadyToSendMessage)
            {
                int message_counter = 0;

                List<Argument> output_arg_lst = new List<Argument>();
                List<Argument> reply_arg_lst = new List<Argument>();

                output_arg_lst.Add(new Argument("first", "1245", DataTypeEnum.integer));
                output_arg_lst.Add(new Argument("second", "aaaBBB", DataTypeEnum.text));
                output_arg_lst.Add(new Argument("third", "3.21", DataTypeEnum.floating_point));

                reply_arg_lst.Add(new Argument("first", DataTypeEnum.integer));
                reply_arg_lst.Add(new Argument("second", DataTypeEnum.text));

                DataLayer.Message m = new DataLayer.Message("get_gripping_point", output_arg_lst, reply_arg_lst, message_counter++, 1000);
                Component.MessageBuffer = m;
            }
        }


        static void xml_ResponseReceived(object sender, MessageStatusArgs args)
        {
            ResponseMessageStatusArgs resp = (ResponseMessageStatusArgs)args;
            Console.WriteLine("Response received to message " + args.MessageNr.ToString() + " : " + resp.Status.ToString()  + " " + resp.Response);
       
        }
        static void xml_MessageSent(object sender, MessageStatusArgs args)
        {
            if (args.Status == MessageStatusEnum.successful)
                Console.WriteLine("Message sent " + (args.MessageNr).ToString());
            else
                Console.WriteLine("Message sending error");
        }
        static void xml_ConnectionEvent(object sender, ConnectionEventArgs args)
        {
            if (args.Status == ConnectionStatusEnum.connected)
            {
                Console.WriteLine("Component connected : " + args.ComponentName + " Componet's address : " + args.Address);
            }
            else if (args.Status == ConnectionStatusEnum.server_set_up)
            {
                Console.WriteLine("Server set up for component : " + args.ComponentName);
            }
            else if (args.Status == ConnectionStatusEnum.connection_error)
            {
                Console.WriteLine("Connection error : " + args.ErrorMessage);
            }
        }

        private static void GUI()
        {
            Application.Run(ServerGui);
        }
        */
     
    }
}
